package com.ourway.controller;

import com.ourway.entity.vo.FeiShuApprovalInfoResponseVo;
import com.ourway.service.IFeiShuService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 审批控制器
 *
 * @author lwh
 * @date 2021/12/03
 */
@RestController
@RequestMapping("/feishu/approval")
public class FeiShuApprovalController {

    private final IFeiShuService IFeiShuService;

    public FeiShuApprovalController(IFeiShuService IFeiShuService) {
        this.IFeiShuService = IFeiShuService;
    }

    /**
     * 通过审批实例
     * @param instanceCode 审批实例Code
     */
    @GetMapping("/approveInstance")
    public void approveInstance(@RequestParam String instanceCode) {
        String accessToken = IFeiShuService.getTenantAccessToken();
        FeiShuApprovalInfoResponseVo approvalInfo = IFeiShuService.getApprovalInfo(accessToken, instanceCode);
        // 同意审批任务
        String approvalCode = approvalInfo.getData().getApproval_code();
        String openId = approvalInfo.getData().getOpen_id();
        String userId = approvalInfo.getData().getUser_id();
        String taskId = approvalInfo.getData().getTask_list().get(0).getId();
        String comment = "ok";
        IFeiShuService.approveInstance(accessToken, approvalCode, instanceCode, openId, userId, taskId, comment);
    }


}
